package com.kaizeli.website.controller;

import com.kaizeli.website.response.Result;
import com.kaizeli.website.service.DatabaseInitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 数据库初始化控制器
 * 用于初始化验收审核相关的数据库表
 */
@Tag(name = "数据库初始化", description = "数据库表初始化相关接口")
@RestController
@RequestMapping("/api/database-init")
public class DatabaseInitController {

    @Autowired
    private DatabaseInitService databaseInitService;

    @Operation(summary = "初始化验收审核相关表")
    @PostMapping("/init-acceptance-tables")
    public Result<Void> initAcceptanceTables() {
        return databaseInitService.initAcceptanceTables();
    }

    @Operation(summary = "检查表是否存在")
    @GetMapping("/check-table/{tableName}")
    public Result<Boolean> checkTableExists(
            @Parameter(description = "表名") @PathVariable String tableName) {
        return databaseInitService.checkTableExists(tableName);
    }

    @Operation(summary = "获取表记录数")
    @GetMapping("/table-count/{tableName}")
    public Result<Integer> getTableRecordCount(
            @Parameter(description = "表名") @PathVariable String tableName) {
        return databaseInitService.getTableRecordCount(tableName);
    }

    @Operation(summary = "获取数据库信息")
    @GetMapping("/database-info")
    public Result<Map<String, Object>> getDatabaseInfo() {
        return databaseInitService.getDatabaseInfo();
    }
}
